import { MockHttp } from './http/index'

const ticketList = [
    {
        card: null,
        endTime: "2022-03-19",
        id: 1,
        image: null,
        isExpired: 1,
        productName: "周黑狗",
        pwd: null,
        startTime: "2022-03-02",
        stockCode: null,
        type: 1,
        typeDesc: "满减券",
        state: 0
    },
    {
        card: null,
        endTime: "2022-03-19",
        id: 2,
        image: null,
        isExpired: 1,
        productName: "周黑狗",
        pwd: null,
        startTime: "2022-03-02",
        stockCode: null,
        type: 2,
        typeDesc: "代金券",
        state: 0
    },
    {
        card: null,
        endTime: "2022-03-19",
        id: 3,
        image: null,
        isExpired: null,
        productName: "周黑狗",
        pwd: null,
        startTime: "2022-03-02",
        stockCode: null,
        type: 3,
        typeDesc: "兑换券",
        state: 0
    },
    {
        card: null,
        endTime: "2022-03-19",
        id: 4,
        image: null,
        isExpired: 1,
        productName: "周黑狗",
        pwd: null,
        startTime: "2022-03-02",
        stockCode: null,
        type: 1,
        typeDesc: "满减券",
        state: 1
    },
    {
        card: null,
        endTime: "2022-03-19",
        id: 5,
        image: null,
        isExpired: 1,
        productName: "周黑狗",
        pwd: null,
        startTime: "2022-03-02",
        stockCode: null,
        type: 2,
        typeDesc: "代金券",
        state: 1
    },
    {
        card: null,
        endTime: "2022-03-19",
        id: 6,
        image: null,
        isExpired: null,
        productName: "周黑狗",
        pwd: null,
        startTime: "2022-03-02",
        stockCode: null,
        type: 3,
        typeDesc: "兑换券",
        state: 1
    },
    {
        card: null,
        endTime: "2022-03-19",
        id: 7,
        image: null,
        isExpired: null,
        productName: "周黑狗",
        pwd: null,
        startTime: "2022-03-02",
        stockCode: null,
        type: 1,
        typeDesc: "满减券",
        state: -1
    },
    {
        card: null,
        endTime: "2022-03-19",
        id: 8,
        image: null,
        isExpired: null,
        productName: "周黑狗",
        pwd: null,
        startTime: "2022-03-02",
        stockCode: null,
        type: 2,
        typeDesc: "代金券",
        state: -1
    },
    {
        card: null,
        endTime: "2022-03-19",
        id: 9,
        image: null,
        isExpired: null,
        productName: "周黑狗",
        pwd: null,
        startTime: "2022-03-02",
        stockCode: null,
        type: 3,
        typeDesc: "兑换券",
        state: -1
    }
]

//创建一个Http的Mock子类
export const mockHttp = new MockHttp()
mockHttp.on('/fakelist', (op) => {
    console.log(op)
    return Promise.resolve({
        success: true,
        data: {
            total:100,
            records: Array.from(ticketList),
            pageSize: 10
        }
    }).delay(3000)
})

mockHttp.on('ticket/detail', (options) => {
    const id = options.query?.id
    if (!id) {
        return Promise.reject(new Error('id不能为空'))
    }
    const ticket = ticketList.find(t => t.id === id)
    if (!ticket) {
        return Promise.reject(new Error('无此id对应的数据'))
    }
    return Promise.resolve(ticket)
})
